<%@ page language="java"
	import="java.util.*"
	import="edu.cnu.tpts.dao.TeacherDao" 
	import="edu.cnu.tpts.dao.impl.TeacherDaoImpl" 
	import="edu.cnu.tpts.bean.Teacher" 
	pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/authorize.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'doupdateMessage.jsp' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

	</head>

	<body>

		<%
			request.setCharacterEncoding("utf-8");
			int id = Integer.parseInt(request.getParameter("id"));
			String password = request.getParameter("password");
			String repassword = request.getParameter("repassword");
			String realname = request.getParameter("realname");
			String loginname=request.getParameter("loginname");
			 TeacherDao teacherDao=new TeacherDaoImpl(); 
			if (password.equals(repassword)) {
				Teacher teacher = teacherDao.findById(id);
				teacher.setPassword(password);
				teacher.setRealName(realname);
				teacher.setLoginName(loginname);
				teacherDao.updateTeacher(teacher);
				String type=(String)session.getAttribute("type");
				if(type.equals("teacher")) //如果是教师更新
					response.sendRedirect("/teacher/index.jsp");
				else  //如果是管理员更新教师信息
				response.sendRedirect("/admin/admin_tea.jsp");
			} else {
					request.setAttribute("error","<font color='red'>密码和确认密码不一致!</font>");
					request.getRequestDispatcher("/teacher/updateTeacher.jsp").forward(request,response);
			}
		%>
	</body>
</html>
